package com.yanfei.zero.infrastructure.mq;

import java.io.IOException;
import java.util.Map;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;
import com.yanfei.zero.infrastructure.config.DirectRabbitConfig;

@Component
@RabbitListener(queuesToDeclare = @Queue(DirectRabbitConfig.TOPIC_EXCHANGE_QUEUE_C))
public class TopicExchangeConsumerC {

    @RabbitHandler
    public void process(Map<String, Object> map,Channel channel,Message msg) throws IOException {
    	long deliverTag = msg.getMessageProperties().getDeliveryTag();
    	try {
    		// 手动消费确认
    		if(deliverTag%2==0) {
    			channel.basicAck(deliverTag, false);
    		}
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			channel.basicNack(deliverTag, false, false);
		}
        System.out.println("死信队列[" + DirectRabbitConfig.TOPIC_EXCHANGE_QUEUE_C + "]收到消息：" + map.toString());
    }
}
